package rwi.informationsystem.internal.clientsimulator;

import java.util.ArrayList;

import rwi.informationsystem.core.interfaces.Client.IVehicleClient;

public class ClientSimulator {

	private IVehicleClient clientservice;
	private ArrayList<Integer> idlist;

	protected void setClient(IVehicleClient value) {
		this.clientservice = value;
	}

	protected void startup() {
		this.idlist = new ArrayList<>();
		simulate(700);
	}

	protected void shutdown() {
		for (int i : idlist) {
			clientservice.unregister(i);
		}
	}

	private void simulate(int count) {
		int o = 0;
		for (int x = 0; x < 500; x += 20) {
			for (int y = 0; y < 500; y += 20) {
				if (o >= count)
					return;
				else {
					try {
						this.idlist.add(clientservice.register(0, x, y));
						o++;
					} catch (Exception ex) {
						System.out.println("Connection Error.");
						return;
					}
				}
			}
		}
	}
}
